package com.wangdao.wechatmall.controller.admin;

import com.wangdao.wechatmall.bean.bo.admin.*;
import com.wangdao.wechatmall.bean.pojo.Ad;
import com.wangdao.wechatmall.bean.pojo.Coupon;
import com.wangdao.wechatmall.bean.pojo.Topic;
import com.wangdao.wechatmall.bean.vo.admin.AdCreateVO;
import com.wangdao.wechatmall.bean.vo.admin.BaseDataVO;
import com.wangdao.wechatmall.bean.vo.admin.BaseRespVo;
import com.wangdao.wechatmall.service.admin.PromotionService;
import com.wangdao.wechatmall.util.ValidatedUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ShuiYi
 * @time 2021-07-09 15:07
 */
@RestController
@RequestMapping("admin")
public class PromotionController {


    /*-----------------广告模块-------------------------*/
    @Autowired
    PromotionService promotionService;

    /**
     *
     * @param adListBO
     * @return
     */
    @RequestMapping("ad/list")
    public BaseRespVo adList(AdListBO adList) {
        BaseDataVO baseDataVO = promotionService.adList(adList);
        return BaseRespVo.ok(baseDataVO);
    }

/*    *//**
     * 文件上传
     * @param file
     * @return
     *//*
    @RequestMapping("storage/create")
    public BaseRespVo storageCreate(MultipartFile file) {
        StorageCreateVO storageCreateVO = promotionService.storageCreate(file);
        return BaseRespVo.ok(storageCreateVO);
    }*/
    @RequestMapping("ad/create")
    public BaseRespVo adCreate(@RequestBody Ad ad) {
        AdCreateVO adCreateVO = promotionService.adCreate(ad);
        return BaseRespVo.ok(adCreateVO);
    }
    @RequestMapping("ad/update")
    public BaseRespVo adUpdate(@RequestBody @Validated Ad ad, BindingResult result) {
        if (result.hasErrors()) {
            return ValidatedUtils.validate(result);
        }
        AdCreateVO adCreateVO = promotionService.adUpdate(ad);
        return BaseRespVo.ok(adCreateVO);
    }
    @RequestMapping("ad/delete")
    public BaseRespVo adDelete(@RequestBody Ad ad) {
        promotionService.adDelete(ad);
        return BaseRespVo.ok("成功");
    }

    /*-----------------------优惠券-----------------------------*/


    @RequestMapping("coupon/list")
    public BaseRespVo couponList(CouponListBO couponListBO) {
        BaseDataVO baseData = promotionService.couponList(couponListBO);
        return BaseRespVo.ok(baseData);
    }
    @RequestMapping("coupon/create")
    public BaseRespVo couponCreate(@RequestBody Coupon coupon) {
        Coupon couponCreate = promotionService.couponCreate(coupon);
        return BaseRespVo.ok(couponCreate);
    }
    @RequestMapping("coupon/read")
    public BaseRespVo couponRead(Integer id) {
        Coupon coupon = promotionService.couponRead(id);
        return BaseRespVo.ok(coupon);
    }
    @RequestMapping("coupon/listuser")
    public BaseRespVo couponListUser(CouponListUserBO couponListUserBO) {
        BaseDataVO baseDataVO = promotionService.couponListUser(couponListUserBO);
        return BaseRespVo.ok(baseDataVO);
    }
    @RequestMapping("coupon/update")
    public BaseRespVo couponUpdate(@RequestBody CouponUpdateBO couponUpdateBO) {
        Coupon coupon = promotionService.couponUpdate(couponUpdateBO);
        return BaseRespVo.ok(coupon);
    }
    @RequestMapping("coupon/delete")
    public BaseRespVo couponDelete(@RequestBody CouponDeleteBO couponDeleteBO) {
        promotionService.couponDelete(couponDeleteBO);
        return BaseRespVo.ok();
    }

    /*--------------------专题-------------------------*/

    @RequestMapping("topic/list")
    public BaseRespVo topicList(TopicListBO topicListBO) {
        BaseDataVO baseDataVO =  promotionService.topicList(topicListBO);
        return BaseRespVo.ok(baseDataVO);
    }
    @RequestMapping("topic/create")
    public BaseRespVo topicCreate(@RequestBody Topic topic) {
        Topic topicVo =  promotionService.topicCreate(topic);
        return BaseRespVo.ok(topicVo);
    }
    @RequestMapping("topic/update")
    public BaseRespVo topicUpdate(@RequestBody Topic topic) {
        Topic topicVo =  promotionService.topicUpdate(topic);
        return BaseRespVo.ok(topicVo);
    }
    @RequestMapping("topic/delete")
    public BaseRespVo topicDelete(@RequestBody Topic topic) {
        promotionService.topicDelete(topic);
        return BaseRespVo.ok();
    }
}
